﻿#include <vector>
#include <iostream>
using namespace std;


struct nodelist
{
	int val;
	nodelist *next;
	nodelist(int x):val(x),next(NULL){}
};

nodelist *reverseNodelist(nodelist *head)
{
   if(head==NULL||head->next==NULL) return head;
	nodelist *t=reverseNodelist(head->next);
	head->next->next=head;
	head->next=NULL;
	return t;

}

nodelist *reverseNodelist2(nodelist *head)
{
	nodelist *pre=NULL;
	nodelist *curr=head;
	while(head!=NULL)
	{
		curr=head->next;
		head->next=pre;
		pre=head;
		head=curr;
	}
	return pre;
	
}

int main()
{
	nodelist *head=new nodelist(0);
	nodelist *head1=new	nodelist(1);
	nodelist *head2=new nodelist(2);
	nodelist *head3=new nodelist(3);
	head->next=head1;
	head1->next=head2;
	head2->next=head3;
	//nodelist *out=reverseNodelist(head);
	nodelist *out2=reverseNodelist2(head);

}